package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.AdministrativeAreaProvider;
import com.jinmdz.fmis.dao.admin.model.administrativearea.AdministrativeAreaEditItem;
import com.jinmdz.fmis.dao.admin.model.administrativearea.AdministrativeAreaListItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 行政区划Dao
 *
 * @author LiCongLu
 * @date 2020-03-15 9:12
 */
public interface AdministrativeAreaDao {


    /**
     * 按照火化炉类型查询行政区划列表
     *
     * @param parentId 父类主键
     * @return
     * @author LiCongLu
     * @date 2020-03-15 9:12
     */
    @SelectProvider(type = AdministrativeAreaProvider.class, method = "listAdministrativeAreaListByParentId")
    ArrayList<AdministrativeAreaListItem> listAdministrativeAreaListByParentId(@Param("parentId") Integer parentId);

    /**
     * 按照父主键获取行政区划个数
     *
     * @param parentId 父主键
     * @return
     * @author LiCongLu
     * @date 2020-03-15 18:58
     */
    @Select(" select count(*) as area_count from system_area where parent_id = #{parentId} and deleted = 0 ")
    @ResultType(Integer.class)
    Integer getAreaCountByParentId(@Param("parentId") Integer parentId);

    /**
     * 按照主键获取行政区划信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-15 9:12
     */
    @SelectProvider(type = AdministrativeAreaProvider.class, method = "getAdministrativeAreaEditById")
    AdministrativeAreaEditItem getAdministrativeAreaEditById(@Param("id") Integer id);

    /**
     * 按照行政区划编码查询非当前行政区划信息主键
     *
     * @param areaId   当前行政区划主键
     * @param areaCode 行政区划编码
     * @return
     * @author LiCongLu
     * @date 2020-03-15 9:12
     */
    @Select(" select id from system_area where id != IFNULL(#{areaId},0) and area_code = #{areaCode} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getAreaIdByAreaCode(@Param("areaId") Integer areaId, @Param("areaCode") String areaCode);

    /**
     * 按照行政区划编码查询当前行政区划信息主键
     *
     * @param areaId   非当前行政区划主键
     * @param areaName 行政区划名称
     * @param parentId 父类主键
     * @return
     * @author LiCongLu
     * @date 2020-03-15 9:12
     */
    @Select(" select id from system_area where id != IFNULL(#{areaId},0) and area_name = #{areaName} and parent_id = #{parentId} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getAreaIdByAreaName(@Param("areaId") Integer areaId, @Param("areaName") String areaName, @Param("parentId") Integer parentId);

}
